import React from 'react'
import type { FC, ReactNode } from 'react'
import { memo } from 'react'
import { Navigate } from 'react-router-dom'

interface Iprops {
  children?: ReactNode
}
const RouterAuth: FC<Iprops> = ({ children }) => {
  const token = localStorage.getItem('h5-token')
  if (!token) {
    // 未登录，跳转到登录页
    return <Navigate to="/login" replace />
  }

  // 已登录，放行
  return children
}
export default memo(RouterAuth)
